package ustc.xiaoyang.karl.linkedlist;
/**
    19.删除链表的倒数第N个结点
 */
public class DeleteSpecifiedNode19 {
    public static void main(String[] args) {

    }
    public static ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0,head);
        ListNode p = dummy, q = dummy;
        for(int i = 0; i < n; i++){
            p = p.next;
        }
        while(p.next != null){
            p = p.next;
            q = q.next;
        }
        q.next = q.next.next;
        return dummy.next;
    }
}
